package com.ct.rabbitmqspringboot.listener;

import com.ct.rabbitmqspringboot.constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/consumer")
public class PullListener {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 拉模式
    // 拉模式是主动的获取消息, 所以我们要发送请求
    @RequestMapping("/pullConsumer")
    public void queueListener() {

        // 这里 Message 包括消息主体和消息的属性
        Message receive = rabbitTemplate.receive(Constants.PULL_QUEUE);
        System.out.println("拉模式: " + receive);
    }
}
